﻿var ArtCtrl = (function () {
	var that;
	var obj = function () {
		that = this;
		that.height = [0, 0, 0];
	};

	obj.prototype = {
		ctrl: function ($scope, $http) {
			that.$scope = $scope;
			that.$http = $http;

			that.$scope.tapIndex = 0;

			that.$scope.showChildPage = that.showChildPage;
			that.$scope.redirect = Util.navChange;
			that.initImage();
			that.initScreening();
		},

		initImage: function () {
			var images = [
				{ src: "image/kong/5.jpg" },
				{ src: "image/kong/6.jpg" },
				{ src: "image/kong/7.jpg" },
				{ src: "image/kong/8.jpg" },
				{ src: "image/kong/9.jpg" },
				{ src: "image/kong/10.jpg" },
				{ src: "image/kong/11.jpg" },
				{ src: "image/kong/12.jpg" },
				{ src: "image/kong/13.jpg" },
				{ src: "image/kong/14.jpg" },
				{ src: "image/kong/15.jpg" },
				{ src: "image/kong/16.jpg" },
				{ src: "image/kong/17.jpg" },
				{ src: "image/kong/18.jpg" },
				{ src: "image/kong/19.jpg" },
				{ src: "image/kong/20.jpg" },
			];

			var divs = document.querySelectorAll("#photo_wall div");
			for (var i = 0; i < images.length; i++) {
				that.loadImage(images[i].src, divs);
			}
		},

		initScreening: function () {
			that.$scope.screeningData = Util.getScreeningData();
		},

		loadImage: function (src, divs) {
			var img = document.createElement("img");
			img.src = src;
			img.onload = function () {
				var index = that._getMinIndex();
				var a = document.createElement("a");
				a.href = "javascript:Util.showChildPage('pages/worksinfo.html')";
				a.appendChild(this);
				divs[index].appendChild(a);
				that.height[index] += this.height;
			}
		},

		showChildPage: function (src) {
			Util.showChildPage(src)
		},

		_getMinIndex: function () {
			var i, v = 100000, index = 0;
			for (i = 0; i < that.height.length; i++) {
				if (v > that.height[i]) {
					v = that.height[i];
					index = i;
				}
			}
			return index;
		}
	};

	return new obj();
})();